package com.hashcoding.eyes.ui.activity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.hashcoding.eyes.R;
import com.hashcoding.eyes.data.entity.LoginInfoList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class RegisterActivity extends BaseActivity {

    @Bind(R.id.username)
    EditText mUsername;
    @Bind(R.id.password)
    EditText mPassword;
    @Bind(R.id.ensure_password)
    EditText mEnsurePassword;
    @Bind(R.id.remember)
    CheckBox mRemember;
    @Bind(R.id.login)
    Button mLogin;
    @Bind(R.id.title_right_btn)
    ImageView mTitleRightBtn;
    @Bind(R.id.title_text)
    TextView mTitleText;

    private String mUserID;
    private String mUserPassword;
    private String mUserEnsurePassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.title_left_btn)
    protected void onTitleLeftClick() {
        onBackPressed();
    }

    @OnClick(R.id.login)
    protected void clickLogin() {
        mUserID = mUsername.getText().toString();
        mUserPassword = mPassword.getText().toString();
        mUserEnsurePassword = mEnsurePassword.getText().toString();

        if (mUserID.isEmpty() || mUserPassword.isEmpty()) {
            shortToast("用户名或密码不能为空");
        }

        if (mUserPassword.equals(mUserEnsurePassword)) {
            if (LoginInfoList.instance().insert(mUserID, mUserPassword)) {
                shortToast("注册成功");
                finish();
            } else {
                shortToast("用户名已经存在");
            }
        } else {
            shortToast("两次密码不相同");
        }
    }
}
